package model

import (
	"gorm.io/gorm"
	__ "video-srv/basic/proto/rpc"
)

type EpisodeLog struct {
	gorm.Model
	VideoId      int `gorm:"type:int" json:"videoId"`
	EpisodeOrder int `gorm:"type:int" json:"episodeOrder"`
	Duration     int `gorm:"type:int" json:"duration"`
}

func (e *EpisodeLog) CreateEpisodeLog(db *gorm.DB) error {
	return db.Create(&e).Error
}
func (e *EpisodeLog) GetEpisodeLogList(db *gorm.DB, page, size int) (list []*__.EpisodeLogList, err error) {
	offset := (page - 1) * size
	err = db.Model(&e).
		Select("title,image,duration").
		Joins("LEFT JOIN videos ON videos.id = episode_logs.video_id").
		Offset(offset).Limit(size).Find(&list).Error
	return
}
